/**
* 作者: lichuan
* 日期: 2025-07-08 14:14:10
* 备注: 玩家高级签到详情表
*/
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserDailyPass;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserDailyPassModel extends BaseModel implements Model {
	public static final String LISTKEY = "";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

	protected long id; // 玩家id
	protected long resetTime; // 重置时间 (每期的结束时间)
	protected String signList = ""; // 签到列表 ([1,2,3,4,5,6,7]])
	protected int groupId; // 当前期数
	protected String signList2 = ""; // 高级签到列表 ([1,2,3,4,5,6,7]])

	public void reset() {
	}

	protected String getKey() {
		return "UserDailyPass." + id;
	}

	protected String getListKey() {
		return null;
	}

	protected String getListItemKey() {
		return null;
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("user_daily_pass"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, id, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	* 根据入库类型更新
	*/
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, id, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	* 实时入库
	*/
	public JsonObject updateNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE_NOW, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	* 实时入队列
	*/
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // 玩家id
		obj.put("resetTime", resetTime); // 重置时间 (每期的结束时间)
		obj.put("signList", signList); // 签到列表 ([1,2,3,4,5,6,7]])
		obj.put("groupId", groupId); // 当前期数
		obj.put("signList2", signList2); // 高级签到列表 ([1,2,3,4,5,6,7]])
		return obj;
	}

	public PBUserDailyPass.Builder takeInitBuilder() {
		PBUserDailyPass.Builder sb = PBUserDailyPass.newBuilder();
		if (this.signList != null && this.signList.length() > 0) {
			JsonArray list = new JsonArray(this.signList);
			for(int i=0; i<list.size(); i++) {
				sb.addSignList(list.getInteger(i));
			}
		}
		if (this.signList2 != null && this.signList2.length() > 0) {
			JsonArray list = new JsonArray(this.signList2);
			for(int i=0; i<list.size(); i++) {
				sb.addSignList2(list.getInteger(i));
			}
		}
		return sb;
	}

	public PBUserDailyPass.Builder takeBuilder() {
		if (updateObj == null || updateObj.isEmpty()) {
			return takeInitBuilder();
		}
		PBUserDailyPass.Builder sb = PBUserDailyPass.newBuilder();
		if (isFieldUpdate("signList")) {
			if (this.signList != null && this.signList.length() > 0) {
				JsonArray list = new JsonArray(this.signList);
				for(int i=0; i<list.size(); i++) {
					sb.addSignList(list.getInteger(i));
				}
				if (list.isEmpty()) {
					sb.clearSignList();
				}
			} else {
				sb.clearSignList();
			}
		}
		if (isFieldUpdate("signList2")) {
			if (this.signList2 != null && this.signList2.length() > 0) {
				JsonArray list = new JsonArray(this.signList2);
				for(int i=0; i<list.size(); i++) {
					sb.addSignList2(list.getInteger(i));
				}
				if (list.isEmpty()) {
					sb.clearSignList2();
				}
			} else {
				sb.clearSignList2();
			}
		}
		return sb;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public long getResetTime() {
		return resetTime;
	}

	public void putResetTime(long resetTime) {
		if (this.resetTime != resetTime) {
			this.resetTime = resetTime;
			updateRedisHashField(getKey(), "resetTime", this.resetTime);
		}
	}

	public void addResetTime(long value) {
		this.resetTime += value;
		updateRedisHashField(getKey(), "resetTime", this.resetTime);
	}

	public JsonArray getSignListArray() {
		if (this.signList != null && this.signList.length() > 0) {
			return new JsonArray(this.signList);
		} else {
			return new JsonArray();
		}
	}

	public String getSignList() {
		return signList;
	}

	public void putSignList(String signList) {
		if (!this.signList.equals(signList)) {
			this.signList = signList;
			updateRedisHashField(getKey(), "signList", this.signList);
		}
	}

	public int getGroupId() {
		return groupId;
	}

	public void putGroupId(int groupId) {
		if (this.groupId != groupId) {
			this.groupId = groupId;
			updateRedisHashField(getKey(), "groupId", this.groupId);
		}
	}

	public void addGroupId(int value) {
		this.groupId += value;
		updateRedisHashField(getKey(), "groupId", this.groupId);
	}

	public JsonArray getSignList2Array() {
		if (this.signList2 != null && this.signList2.length() > 0) {
			return new JsonArray(this.signList2);
		} else {
			return new JsonArray();
		}
	}

	public String getSignList2() {
		return signList2;
	}

	public void putSignList2(String signList2) {
		if (!this.signList2.equals(signList2)) {
			this.signList2 = signList2;
			updateRedisHashField(getKey(), "signList2", this.signList2);
		}
	}

}